package cn.sfa.service.promote;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

import cn.sfa.common.pagination.Pagination;
import cn.sfa.entity.manage.SaleProduct;
import cn.sfa.entity.promote.Salepromote;

/**
 * 显示头条晋升的类
 * @author hui
 *
 */
public class PromoteSerice {
	@Autowired
	NamedParameterJdbcTemplate jdbcTemplate;
	/**
	 * 查询晋升的人
	 */
	public Pagination seachPromot(
			int currentPage,// 页码
			int numPerPage,// 页尺寸
			String url,// 分页url
			String currentBranchId, //机构id
			int number
			){	
		Map<String, Object> paraMap = new HashMap<String, Object>();
		StringBuilder sqlStr = new StringBuilder(); 
		sqlStr.append(" select * from ( ");
		sqlStr.append(" select ag.agentid,ag.agentlogid, ag.agentname,ag.agentcode,ag.cbranchid, ch.remark , ");
		sqlStr.append(" ch.changedate, ch.applyno, ch.beforevalue,ch.aftervalue, sd.chnname from  changelog ch ");
		sqlStr.append(" right join agentlog ag on  ch.agentid = ag.agentid ");
		sqlStr.append(" left join syscode sd on sd.recordid = ch.aftervalue ");
		sqlStr.append(" where remark like '%更变上级管理人%' or remark like '%晋升%' and pbranchid  =:currentBranchId ");
		sqlStr.append(" order by ch.changedate desc nulls last ) ");
		if(number>0)
			sqlStr.append(" where ROWNUM <= "+number);	 
		paraMap.put("currentBranchId", currentBranchId);
		return new Pagination(sqlStr.toString(), paraMap, currentPage,
				numPerPage, url, jdbcTemplate);

	}
}
